import re

# 获取字符串
#列表项=["2727","12313","5×4×2MM"]
#input_string = '5×4×2MM'
input_string=列表项[2].replace('mm','MM').replace('*','×').replace('X','×').replace('x','×')


pattern_1 = r'(\d+(\.\d+)?)×(\d+(\.\d+)?)×(\d+(\.\d+)?)MM'
pattern_2 = r'Ф\((\d+(\.\d+)?)×(\d+(\.\d+)?)\)×(\d+(\.\d+)?)MM'
pattern_3 = r'(\d+(\.\d+)?)×(\d+(\.\d+)?)×R角(\d+(\.\d+)?)MM'
pattern_4 = r'直径(\d+(\.\d+)?)MM'
pattern_5 = r'(\d+(\.\d+)?)×(\d+(\.\d+)?)MM'
pattern_6 = r'(\d+(\.\d+)?)MM卷'
pattern_7 = r'外直径(\d+(\.\d+)?)×高(\d+(\.\d+)?)MM'
pattern_8 = r'(\d+(\.\d+)?)MM×(\d+(\.\d+)?)M'
pattern_9 = r'Ф(\d+(\.\d+)?)×(\d+(\.\d+)?)MM'

# 使用正则表达式查找匹配项
match_1 = re.match(pattern_1, input_string)
match_2 = re.match(pattern_2, input_string)
match_3 = re.match(pattern_3, input_string)
match_4 = re.match(pattern_4, input_string)
match_5 = re.match(pattern_5, input_string)
match_6 = re.match(pattern_6, input_string)
match_7 = re.match(pattern_7, input_string)
match_8 = re.match(pattern_8, input_string)
match_9 = re.match(pattern_9, input_string)

Specification_template = ''
# 提取匹配到的数字并返回结果列表
if match_1:
    numbers = [float(match_1.group(i)) for i in range(1, len(match_1.groups()) + 1, 2)]
    Specification_template = "长×宽×高（厚）"
elif match_2:
    numbers = [float(match_2.group(i)) for i in range(1, len(match_2.groups()) + 1, 2)]
    Specification_template = "Ф(长×宽)×高"
elif match_3:
    Specification_template = "长×宽×R角"
    numbers = [float(match_3.group(i)) for i in range(1, len(match_3.groups()) + 1, 2)]
elif match_4:
    Specification_template = "直径"
    numbers = [float(match_4.group(i)) for i in range(1, len(match_4.groups()) + 1, 2)]
elif match_5:
    Specification_template = "长×宽（或宽×长）"
    numbers = [float(match_5.group(i)) for i in range(1, len(match_5.groups()) + 1, 2)]
elif match_6:
    Specification_template = "宽幅"
    numbers = [float(match_6.group(i)) for i in range(1, len(match_6.groups()) + 1, 2)]
elif match_7:
    Specification_template = "外直径×圆筒高度"
    numbers = [float(match_7.group(i)) for i in range(1, len(match_7.groups()) + 1, 2)]
elif match_8:
    Specification_template = "宽度×长"
    numbers = [float(match_8.group(i)) for i in range(1, len(match_8.groups()) + 1, 2)]
elif match_9:
    Specification_template = "Ф×高"
    numbers = [float(match_9.group(i)) for i in range(1, len(match_9.groups()) + 1, 2)]
else:
    numbers = []

# 小数点后为0的float转为int
长宽厚 = [int(value) if value.is_integer() else value for value in numbers]


print(f'匹配到的数字是：{长宽厚}，分类为：{Specification_template}')
# Log.Info(self, "匹配到的数字是：{matched_numbers}，分类为：{Specification_template}")
